package com.qfedu.dao;

import com.qfedu.model.ProductBatches;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface ProductBatchesDao {
    //根据id查询
    @Select("select * from product_batches where id = #{id} ")
    List<ProductBatches> findProductBatchesById(int id);

    //增加
    @Insert("insert into product_batches (productName,isactive,productBatch,area,recoverydate,img,feature,sysUserId,farmId) values(#{productName},"+
            ",#{isactive},#{productBatch},#{area},#{recoverydate},#{img},#{feature},#{sysUserId},#{farmId})")
    void addProductBatches(ProductBatches productBatches);

    //修改
    @Update("update product_batches set productName=#{productName},isactive=#{isactive},productBatch=#{productBatch},area=#{area},"+
            ",recoverydate=#{recoverydate},img=#{img},feature=#{feature},sysUserId=#{sysUserId},farmId=#{farmId} where id = #{id}")
    void updateProductBatches(ProductBatches productBatches);

    //删除
    @Delete("delete from product_batches where id=#{id}")
    void deleteProductBatches(int id);

    //查询所有
    @Results(id = "findAll",value = {
            @Result(property = "productName",column = "product_name"),
            @Result(property = "isactive",column = "isactive"),
            @Result(property = "productBatch",column = "product_batch"),
            @Result(property = "area",column = "area"),
            @Result(property = "recoverydate",column = "recoverydate"),
            @Result(property = "img",column = "img"),
            @Result(property = "feature",column = "feature"),
            @Result(property = "sysUserId",column = "sys_user_id"),
            @Result(property = "farmId",column = "farm_id"),
            @Result(property = "sysUser",column = "id",
                    one = @One(select = "com.qfedu.dao.SysUserDao.findSysUserByid",fetchType = FetchType.EAGER)),
            @Result(property = "tfarm",column = "id",
                    one = @One(select = "com.qfedu.dao.TFarmDao.findTFarmByid",fetchType = FetchType.EAGER))
    })
    @Select("select * from product_batches")
    List<ProductBatches> findAllProductBatches();
}
